package com.hotau.setting;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hotau.R;

/**
 * 系统设置
 * 
 * @author hanshengliang
 * @data 2011-12-10
 * @version 1.0
 *          <ul>
 *          <li>1.0 创建</li>
 *          </ul>
 */
public class SettingHelpFragment extends Fragment  implements OnClickListener{

	public static final String TAG = "SettingHelpFragment";
	private TextView mTextView[]=new TextView[7];
	private ImageView mImageViewOn[]=new ImageView[7];
	private ImageView mImageViewOff[]=new ImageView[7];
	private LinearLayout mLinearLayout[]=new LinearLayout[7];
	private ImageView mPhone=null;

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onActivityCreated(savedInstanceState);
		initAllWidget();
		initAllEvent();
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		return inflater.inflate(R.layout.setting_help_view, container, false);
	}
	/**
	 * 初始化所有控件
	 */
	public void initAllWidget() {
		mImageViewOn[0] = (ImageView) getActivity().findViewById(R.id.setting_help_a1_on);
		mImageViewOff[0] = (ImageView) getActivity().findViewById(R.id.setting_help_a1_off);
		mTextView[0] = (TextView) getActivity().findViewById(R.id.setting_help_a1);
		mImageViewOn[1] = (ImageView) getActivity().findViewById(R.id.setting_help_a2_on);
		mImageViewOff[1] = (ImageView) getActivity().findViewById(R.id.setting_help_a2_off);
		mTextView[1] = (TextView) getActivity().findViewById(R.id.setting_help_a2);
		mImageViewOn[2] = (ImageView) getActivity().findViewById(R.id.setting_help_a3_on);
		mImageViewOff[2] = (ImageView) getActivity().findViewById(R.id.setting_help_a3_off);
		mTextView[2] = (TextView) getActivity().findViewById(R.id.setting_help_a3);
		mImageViewOn[3] = (ImageView) getActivity().findViewById(R.id.setting_help_a4_on);
		mImageViewOff[3] = (ImageView) getActivity().findViewById(R.id.setting_help_a4_off);
		mTextView[3] = (TextView) getActivity().findViewById(R.id.setting_help_a4);
		mImageViewOn[4] = (ImageView) getActivity().findViewById(R.id.setting_help_a5_on);
		mImageViewOff[4] = (ImageView) getActivity().findViewById(R.id.setting_help_a5_off);
		mTextView[4] = (TextView) getActivity().findViewById(R.id.setting_help_a5);
		mImageViewOn[5] = (ImageView) getActivity().findViewById(R.id.setting_help_a6_on);
		mImageViewOff[5] = (ImageView) getActivity().findViewById(R.id.setting_help_a6_off);
		mTextView[5] = (TextView) getActivity().findViewById(R.id.setting_help_a6);
		mImageViewOn[6] = (ImageView) getActivity().findViewById(R.id.setting_help_a7_on);
		mImageViewOff[6] = (ImageView) getActivity().findViewById(R.id.setting_help_a7_off);
		mTextView[6] = (TextView) getActivity().findViewById(R.id.setting_help_a7);
		
		mLinearLayout[0] = (LinearLayout) getActivity().findViewById(R.id.setting_help_q1_linearlayout);
		mLinearLayout[1] = (LinearLayout) getActivity().findViewById(R.id.setting_help_q2_linearlayout);
		mLinearLayout[2] = (LinearLayout) getActivity().findViewById(R.id.setting_help_q3_linearlayout);
		mLinearLayout[3] = (LinearLayout) getActivity().findViewById(R.id.setting_help_q4_linearlayout);
		mLinearLayout[4] = (LinearLayout) getActivity().findViewById(R.id.setting_help_q5_linearlayout);
		mLinearLayout[5] = (LinearLayout) getActivity().findViewById(R.id.setting_help_q6_linearlayout);
		mLinearLayout[6] = (LinearLayout) getActivity().findViewById(R.id.setting_help_q7_linearlayout);
		mPhone=(ImageView) getActivity().findViewById(R.id.setting_help_phone_click);
	}

	/**
	 * 初始化所有事件
	 */
	public void initAllEvent() {
//		mImageViewOn[0].setOnClickListener(this);
//		mImageViewOff[0].setOnClickListener(this);
//		mImageViewOn[1].setOnClickListener(this);
//		mImageViewOff[1].setOnClickListener(this);
//		mImageViewOn[2].setOnClickListener(this);
//		mImageViewOff[2].setOnClickListener(this);
//		mImageViewOn[3].setOnClickListener(this);
//		mImageViewOff[3].setOnClickListener(this);
//		mImageViewOn[4].setOnClickListener(this);
//		mImageViewOff[4].setOnClickListener(this);
//		mImageViewOn[5].setOnClickListener(this);
//		mImageViewOff[5].setOnClickListener(this);
//		mImageViewOn[6].setOnClickListener(this);
//		mImageViewOff[6].setOnClickListener(this);
		mLinearLayout[0].setOnClickListener(this);
		mLinearLayout[1].setOnClickListener(this);
		mLinearLayout[2].setOnClickListener(this);
		mLinearLayout[3].setOnClickListener(this);
		mLinearLayout[4].setOnClickListener(this);
		mLinearLayout[5].setOnClickListener(this);
		mLinearLayout[6].setOnClickListener(this);
		mPhone.setOnClickListener(this);
		
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.setting_help_q1_linearlayout:
			int v1=mTextView[0].getVisibility();	
			if(v1==View.GONE){
				onClickIndex(1,true);
			}else{
				onClickIndex(1,false);
			}
			break;
		case R.id.setting_help_q2_linearlayout:
			int v2=mTextView[1].getVisibility();	
			if(v2==View.GONE){
				onClickIndex(2,true);
			}else{
				onClickIndex(2,false);
			}
			break;
		case R.id.setting_help_q3_linearlayout:
			int v3=mTextView[2].getVisibility();	
			if(v3==View.GONE){
				onClickIndex(3,true);
			}else{
				onClickIndex(3,false);
			}
			break;
		case R.id.setting_help_q4_linearlayout:
			int v4=mTextView[3].getVisibility();	
			if(v4==View.GONE){
				onClickIndex(4,true);
			}else{
				onClickIndex(4,false);
			}
			break;
		case R.id.setting_help_q5_linearlayout:
			int v5=mTextView[4].getVisibility();	
			if(v5==View.GONE){
				onClickIndex(5,true);
			}else{
				onClickIndex(5,false);
			}
			break;
		case R.id.setting_help_q6_linearlayout:
			int v6=mTextView[5].getVisibility();	
			if(v6==View.GONE){
				onClickIndex(6,true);
			}else{
				onClickIndex(6,false);
			}
			break;
		case R.id.setting_help_q7_linearlayout:
			int v7=mTextView[6].getVisibility();	
			if(v7==View.GONE){
				onClickIndex(7,true);
			}else{
				onClickIndex(7,false);
			}
			break;
			
		case R.id.setting_help_phone_click:
			Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + getString(R.string.setting_help_phonenumber)));
            getActivity().startActivity(intent);
			break;
		default:
			break;
		}
	}
	public void onClickIndex(int index,boolean show) {
		for(int i=1;i<8;i++){
			if(i==index&&show){
				mImageViewOn[i-1].setVisibility(View.GONE);
				mImageViewOff[i-1].setVisibility(View.VISIBLE);
				(mTextView[i-1]).setVisibility(View.VISIBLE);	
			}else{
				(mTextView[i-1]).setVisibility(View.GONE);
				mImageViewOn[i-1].setVisibility(View.VISIBLE);
				mImageViewOff[i-1].setVisibility(View.GONE);
			}
		}
	}
}
